package core.todo.dao;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

import core.todo.domain.Todo;


public class TodoDAOTest1 {

	private static TodoDAO dao = new TodoDAO();
	private static Long mID;
	
    private static final LocalServiceTestHelper helper =
        new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());

    @BeforeClass
    public static void setUp() {
        helper.setUp();
    }

    @AfterClass
    public static void tearDown() {
        helper.tearDown();
    }

	
    @Test
	public void testCreate() {
		Todo newInstance = new Todo(null, "title", "description", new java.util.Date(), false);
		dao.create(newInstance);
		mID = newInstance.getId();
		System.out.println("create: success ");
	}
	
	
	@Test
	public void testFindall() {
		List<Todo> todos = dao.findAll();
		System.out.println("findall: " + todos);
		
	}
	@Test
	public void testFindById() {
		Todo todo = dao.findById(mID);
		System.out.println("findbyId: " + todo);
	}	
	@Test
	public void clean() {
		List<Todo> todos = dao.findAll();
		for (Todo todo: todos) {
			dao.delete(todo.getId());
		}
		System.out.println("cleaned up");
	}

}
